<?php
    require('conn.cfg.php');    
    require('functions.php');
    $msg = '';
    $billEmailAddress_SS  = '';
    $shipfname_SS      = '';
    $billfname_SS      = '';
    $shiplname_SS      = '';   
    $billlname_SS      = '';
    $shipPhone_SS      = '';
    $billPhone_SS      = '';
    $shipAddress1_SS   = '';
    $billAddress1_SS   = '';    
    $shipAddress2_SS   = '';
    $billAddress2_SS   = '';
    $shipCity_SS       = '';
    $billCity_SS       = '';
    $shipState_SS      = '';
    $billState_SS      = '';
    $shipPostalcode_SS = '';
    $billPostalcode_SS = '';
    $shipCountry_SS    = 'US';
    $billCountry_SS    = 'US';
    
    if(isset($_SESSION['address']) && is_array($_SESSION['address'])){
            
        $billEmailAddress_SS = $_SESSION['address']['billEmailAddress'];            
        $billfname_SS = $_SESSION['address']['billFirstName'];
        $billlname_SS = $_SESSION['address']['billLastName'];
        $billPhone_SS = $_SESSION['address']['billHomePhone'];
        $billAddress1_SS = $_SESSION['address']['billAddress1'];
        $billAddress2_SS = $_SESSION['address']['billAddress2'];
        $billCity_SS = $_SESSION['address']['billCity'];
        $billState_SS = $_SESSION['address']['billState'];
        $billPostalcode_SS = $_SESSION['address']['billPostalcode'];
        $billCountry_SS = $_SESSION['address']['billCountry'];

        $shipfname_SS = $_SESSION['address']['shipFirstName'];
        $shiplname_SS = $_SESSION['address']['shipLastName'];
        $shipPhone_SS = $_SESSION['address']['shipHomePhone'];
        $shipAddress1_SS = $_SESSION['address']['shipAddress1'];
        $shipAddress2_SS = $_SESSION['address']['shipAddress2'];
        $shipCity_SS = $_SESSION['address']['shipCity'];
        $shipState_SS = $_SESSION['address']['shipState'];
        $shipPostalcode_SS = $_SESSION['address']['shipPostalcode'];
        $shipCountry_SS = $_SESSION['address']['shipCountry'];
        
        unset($_SESSION['address']);
    }
    
    if(isset($_REQUEST['billFirstName']) && isset($_REQUEST['pass1']) && isset($_REQUEST['email'])){
				
        $email = mysql_real_escape_string($_REQUEST['email']);
        $password = mysql_real_escape_string($_REQUEST['pass1']);		
        $billfname = mysql_real_escape_string($_REQUEST['billFirstName']);
        $billlname = mysql_real_escape_string($_REQUEST['billLastName']);
        $billPhone = mysql_real_escape_string($_REQUEST['billPhone']);
        $address1 = mysql_real_escape_string($_REQUEST['billStreet1']);
        $address2 = mysql_real_escape_string($_REQUEST['billStreet2']);
        $city = mysql_real_escape_string($_REQUEST['billCity']);
        $state = mysql_real_escape_string($_REQUEST['billState']);
        $postalcode = mysql_real_escape_string($_REQUEST['billPostalcode']);
        $country = mysql_real_escape_string($_REQUEST['billCountry']);
        
        $oneContact = $_REQUEST['oneContact'];
        
        if($oneContact == 'on'){
            $shipfname      = $billfname;
            $shiplname      = $billlname;   
            $shipPhone      = $billPhone;
            $shipAddress1   = $address1;
            $shipAddress2   = $address2;
            $shipCity       = $city;
            $shipState      = $state;
            $shipPostalcode = $postalcode;
            $shipCountry    = $country;
        }else{
            $shipfname = mysql_real_escape_string($_REQUEST['shipFirstName']);
            $shiplname = mysql_real_escape_string($_REQUEST['shipLastName']);
            $shipPhone = mysql_real_escape_string($_REQUEST['shipPhone']);
            $shipAddress1 = mysql_real_escape_string($_REQUEST['shipStreet1']);
            $shipAddress2 = mysql_real_escape_string($_REQUEST['shipStreet2']);
            $shipCity = mysql_real_escape_string($_REQUEST['shipCity']);
            $shipState = mysql_real_escape_string($_REQUEST['shipState']);
            $shipPostalcode = mysql_real_escape_string($_REQUEST['shipPostalcode']);
            $shipCountry = mysql_real_escape_string($_REQUEST['shipCountry']);
        }
        
        if(isUserExist($email)){
            $msg = 'Your email was taken, please enter a new one';
        }else{
            saveNewUser($billfname, MD5($password), $billlname, $email, $billPhone, $address1, $address2, $city, $state, $postalcode, $country, $shipfname, $shiplname, $shipAddress1, $shipAddress2, $shipCity, $shipState, $shipPostalcode, $shipPhone, $shipCountry);
            $msg = 'User was saved sucessfully.';
        }
    }
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>X2PERFORMANCE :: Sign up</title>
<link rel="stylesheet" href="assets/css/reset.css" />
<link rel="stylesheet" href="assets/css/text.css" />
<link rel="stylesheet" href="assets/css/960.css" />
<link rel="stylesheet" href="assets/css/style.css" />
<link rel="stylesheet" href="assets/css/general.css" />
<link rel="SHORTCUT ICON" href="favicon.ico"/>
<script type="text/javascript" src="assets/js/jquery-1.5.2.min.js"></script>
<script type="text/javascript" src="assets/js/kickstart.js"></script>
<script type="text/javascript" src="assets/js/script00.js"></script>
<script type="text/javascript" src="assets/js/skimlink.js"></script>
<script type="text/javascript" src="assets/js/jquery.cycle.js"></script>
<script type="text/javascript" src="assets/js/slideshow.js"></script>
<script type="text/javascript" src="assets/js/validation.js"></script>
<link rel="stylesheet" href="assets/css/coda-slider.css" type="text/css" media="screen" title="no title" charset="utf-8">
<script src="assets/js/jquery_002.js" type="text/javascript"></script>
<script src="assets/js/jquery_003.js" type="text/javascript" charset="utf-8"></script>
<script src="assets/js/jquery.js" type="text/javascript" charset="utf-8"></script>
<!--<script src="assets/js/coda-slider.js" type="text/javascript" charset="utf-8"></script>-->

<!--[if IE 7]>
	<style>
    #bottle{ margin-left:-335px;}
    #nav {height:45px;}
    #nav li { display: inline;margin-bottom:8px;}
    </style>
<![endif]-->
<!-- CuFon: Enables smooth pretty custom font rendering. 100% SEO friendly. To disable, remove this section -->
<script type="text/javascript" src="assets/js/cufon-yui.js"></script>
<script type="text/javascript" src="assets/js/PT_Sans_400-PT_Sans_700-PT_Sans_italic_400-PT_Sans_italic_700.font.js"></script>
<script type="text/javascript" src="assets/js/cuf_run.js"></script>
<!-- CuFon ends -->
</head>
<body>
    
<div  id="header">
  <div class="container_16">
    <noscript>
    <div class="alert"> In order to be able to view this website, Javascript needs to be active in your web browser. </div>
    </noscript>
    <div class="grid_8"> <a id="logo" href="index.html" title="X2 Performance"></a> </div>
    <div class="grid_3"> <a id="nsf" href="http://nsfsport.com/listings/certified_detail.asp?id=707999" title="NSF Certified for Sport" target="_blank"></a> </div>
    <div class="grid_5" id="topnavigation">
      <ul id="topnav">
        <!--<li><a href="">Login</a></li>
         <li><a>|</a></li>
        <li><a href="">Register</a></li>-->
        <li><span class="viewcart"></span><a href="x2cart.php">View cart</a></li>
      </ul>
    </div>
    <div class="clear"></div>
    <div class="grid_16" id="navigation">
      <ul id="nav">
        <li class="current_page_item"><a href="index.html" class="home homeactive">Home</a></li>
        <li><a href="about_us.html" class="aboutcompany">About Us</a></li>
        <li><a href="services.html" class="x2performance">X<sup>2</sup>PERFORMANCE</a></li>
        <li><a href="sport.html" class="sportcertified">Sportcertified</a></li>
        <li><a href="contact_us.html" class="contact">Contact Us</a></li>
        <li><a href="blog.html" class="blog">Blog</a></li>
      </ul>
      <!--ul class="order">
        <li><a href="order_now.html" class="ordernow">Order now</a></li>
      </ul-->
    </div>
  </div>
</div>
<div class="container_16">
  <div class="grid_16 innerheader">
    <div class="innerheaderbg"></div>
    <h2>Sign Up</h2>
  </div>
  <div class="clear"></div>  
  <div id="productGrid">        
    <div id="contentUserSignUp">        
        <h4><?php if (isset($msg)){ echo $msg;}?></h4>      
        <div id="containerSignUp" class="boxSignUp">
<script language="javascript">
    $(document).ready(function(){
        $("#billCountry").val("US");
        $("#shipCountry").val("US");
        
        //init billing & shipping address
        $("#email").val('<?=$billEmailAddress_SS?>');
        $("#billFirstName").val('<?=$billfname_SS?>');
        $("#billLastName").val('<?=$billlname_SS?>'); 
        $("#billStreet1").val('<?=$billAddress1_SS?>'); 
        $("#billStreet2").val('<?=$billAddress2_SS?>'); 
        $("#billCity").val('<?=$billCity_SS?>'); 
        $("#billPhone").val('<?=$billPhone_SS?>');
        $("#billState").val('<?=$billState_SS?>'); 
        $("#billPostalcode").val('<?=$billPostalcode_SS?>'); 

        $("#shipFirstName").val('<?=$shipfname_SS?>');
        $("#shipLastName").val('<?=$shiplname_SS?>'); 
        $("#shipStreet1").val('<?=$shipAddress1_SS?>'); 
        $("#shipStreet2").val('<?=$shipAddress2_SS?>'); 
        $("#shipCity").val('<?=$shipCity_SS?>'); 
        $("#shipPhone").val('<?=$shipPhone_SS?>');
        $("#shipState").val('<?=$shipState_SS?>'); 
        $("#shipPostalcode").val('<?=$shipPostalcode_SS?>'); 

        $("#oneContact").click(function(){
            dupplicateAddress();            
        });
    });
</script>            
            <div class="contentSignUp">
                <form method="post" name="customSignup" id="customSignup">
		<div class="title">Login Information</div>
                </br>
                <table>
                    <tbody><tr>
                            <th><span class="required">*</span> E-mail</th>
                            <td><input type="text" autocomplete="off" maxlength="50" size="30" value="" id="email" name="email" class="validate_required"></td>
                            <td><span id="emailInfo"></span></td>
                    </tr>
                    <tr>
                            <th><span class="required">*</span> Password</th>
                            <td><input type="password" autocomplete="off" value="" maxlength="20" size="30" id="pass1" name="pass1" class="validate_required"></td>
                            <td><span id="pass1Info"></span></td>
                    </tr>
                    <tr>
                            <th><span class="required">*</span> Confirm Password</th>
                            <td><input type="password" autocomplete="off" value="" maxlength="20" size="30" id="pass2" name="pass2" class="validate_required"></td>
                            <td><span id="pass2Info"></span></td>
                    </tr>
                    </tbody>
                </table>            
                </br>
                <div class="title">Billing Address</div>
                </br>
                <table>
                    <tbody>
                    <tr>
                        <th><span class="required">*</span> Country</th>
                        <td>
                            <select name="billCountry" id="billCountry">
<?php
    $result = mysql_query("SELECT countrycode, countryname FROM x2_country");
    while ($row = mysql_fetch_assoc($result)) {?>
                            <option value="<?=$row['countrycode']?>"><?=$row['countryname']?></option>                                   
<?php }?>			
                            </select>	
                        </td>
                        <td></td>
                    </tr>    
                    <tr>
                        <th><span class="required">*</span> First Name</th>
                        <td><input type="text" autocomplete="off" value="" maxlength="14" size="25" id="billFirstName" name="billFirstName" class="validate_required"></td>
                        <td><span id="billFirstNameInfo"></span></td>
                    </tr>
                    <tr>
                        <th><span class="required">*</span> Last Name</th>
                        <td><input type="text" autocomplete="off" value="" maxlength="14" size="25" id="billLastName" name="billLastName" class="validate_required"></td>
                        <td><span id="billLastNameInfo"></span></td>
                    </tr>
                    <tr>
                        <th><span class="required">*</span> Street Address 1</th>
                        <td><input type="text" autocomplete="off" value="" maxlength="30" size="25" id="billStreet1" name="billStreet1" class="validate_required"></td>
                        <td><span id="billStreet1Info"></span></td>
                    </tr>
                    <tr>
                        <th>Street Address 2</th>
                        <td><input type="text" autocomplete="off" value="" maxlength="30" size="25" id="billStreet2" name="billStreet2"></td>
                    </tr>
                    <tr>
                        <th><span class="required">*</span> City</th>
                        <td><input type="text" autocomplete="off" value="" maxlength="15" size="25" id="billCity" name="billCity" class="validate_required"></td>
                        <td><span id="billCityInfo"></span></td>
                    </tr>
                    <tr>
                       <th><span class="required">*</span> State</th> 
                       <td>
                        <select name="billState" id="billState">
                            <option value="">Pick State</option>                        
<?php
    $result = mysql_query("SELECT statecode, statename FROM x2_state");
    while ($row = mysql_fetch_assoc($result)) {?>
                            <option value="<?=$row['statecode']?>"><?=$row['statename']?></option>                                   
<?php }?>                        
                           </select>                           
                       </td>
                       <td><span id="billStateInfo"></span></td>
                    </tr>
                    <tr>
                        <th><span class="required">*</span> Zip code</th>
                        <td><input type="text" autocomplete="off" value="" maxlength="15" size="25" name="billPostalcode" id="billPostalcode"  class="validate_required"></td>
                        <td><span id="billPostalcodeInfo"></span></td>
                    </tr>
                    <tr>
                        <th><span class="required">*</span> Phone</th>
                        <td><input type="text" autocomplete="off" value="" maxlength="16" size="15" id="billPhone" name="billPhone" class="validate_required"></td>
                        <td><span id="billPhoneInfo"></span></td>
                    </tr>
                    </tbody>
                </table>
                </br>
                <div class="title">Shipping Address</div>
                </br>
                <table>
                    <tbody>
                    <tr>
                        <th><input type="checkbox" value="on" name="oneContact" id="oneContact"></th>
                        <td colspan="2"><label for="oneContact">Check here if billing and shipping addresses are the same and we will fill out the shipping address for you.</label></td>
                    </tr>                        
                    <tr>
                        <th><span class="required">*</span> Country</th>
                        <td>
                            <select name="shipCountry" id="shipCountry">
<?php
    $result = mysql_query("SELECT countrycode, countryname FROM x2_country");
    while ($row = mysql_fetch_assoc($result)) {?>
                            <option value="<?=$row['countrycode']?>"><?=$row['countryname']?></option>                                   
<?php }?>			
                            </select>	
                        </td>
                        <td></td>
                    </tr>    
                    <tr>
                        <th><span class="required">*</span> First Name</th>
                        <td><input type="text" autocomplete="off" value="" maxlength="14" size="25" id="shipFirstName" name="shipFirstName" class="validate_required"></td>
                        <td><span id="shipFirstNameInfo"></span></td>
                    </tr>
                    <tr>
                        <th><span class="required">*</span> Last Name</th>
                        <td><input type="text" autocomplete="off" value="" maxlength="14" size="25" id="shipLastName" name="shipLastName" class="validate_required"></td>
                        <td><span id="shipLastNameInfo"></span></td>
                    </tr>
                    <tr>
                        <th><span class="required">*</span> Street Address 1</th>
                        <td><input type="text" autocomplete="off" value="" maxlength="30" size="25" id="shipStreet1" name="shipStreet1" class="validate_required"></td>
                        <td><span id="shipStreet1Info"></span></td>
                    </tr>
                    <tr>
                        <th>Street Address 2</th>
                        <td><input type="text" autocomplete="off" value="" maxlength="30" size="25" id="shipStreet2" name="shipStreet2"></td>
                    </tr>
                    <tr>
                        <th><span class="required">*</span> City</th>
                        <td><input type="text" autocomplete="off" value="" maxlength="15" size="25" id="shipCity" name="shipCity" class="validate_required"></td>
                        <td><span id="shipCityInfo"></span></td>
                    </tr>
                    <tr>
                       <th><span class="required">*</span> State</th> 
                       <td>
                        <select name="shipState" id="shipState">
                            <option value="">Pick State</option>                        
<?php
    $result = mysql_query("SELECT statecode, statename FROM x2_state");
    while ($row = mysql_fetch_assoc($result)) {?>
                            <option value="<?=$row['statecode']?>"><?=$row['statename']?></option>                                   
<?php }?>                        
                           </select>                           
                       </td>
                       <td><span id="shipStateInfo"></span></td>
                    </tr>
                    <tr>
                        <th><span class="required">*</span> Zip code</th>
                        <td><input type="text" autocomplete="off" value="" maxlength="15" size="25" name="shipPostalcode" id="shipPostalcode"  class="validate_required"></td>
                        <td><span id="shipPostalcodeInfo"></span></td>
                    </tr>
                    <tr>
                        <th><span class="required">*</span> Phone</th>
                        <td><input type="text" autocomplete="off" value="" maxlength="16" size="15" id="shipPhone" name="shipPhone" class="validate_required"></td>
                        <td><span id="shipPhoneInfo"></span></td>
                    </tr>
                    </tbody>
                </table>
                </br>
                <div>
                        <input id="send" name="send" type="submit" value="Submit">
                </div>
        </form>
           </div> 
	</div>        
    </div>                 	
  </div>

</div>
<br clear="all">
<div id="footer">
  <div class="container_16">
    <div id="footersectionone">
      <div class="grid_1">
        <h3><a href="index.html">Home</a></h3>
      </div>
      <div class="grid_3 footermenucontainer">
        <h3><a href="about_us.html">About Us</a></h3>
        <ul class="mainlinks">
          <li><a href="about_us.html#ceomessage">CEO Message</a></li>
        </ul>
      </div>
      <div class="grid_3 footermenucontainer">
        <h3><a href="services.html">X<sup>2</sup>PERFORMANCE</a></h3>
        <ul class="mainlinks">
          <li><a href="services.html#science">Science</a></li>
          <li><a href="supplymentfacts.html">Supplement facts</a></li>
          <li><a href="instruction.html">Instructions</a></li>
          <li><a href="pricing.html">Pricing</a></li>
          <li><a href="testimonial.php">Testimonials</a></li>
        </ul>
      </div>
      
      <div class="grid_2">
        <h3><a href="contact_us.html">Contact Us</a></h3>
        <ul class="mainlinks">
          <li><a href="privacy.html">Privacy Policy</a></li>
          <li><a href="terms.html">Terms</a></li>
        </ul>
      </div>
      <div class="grid_2">
        <h3><a href="sport.html">Sport certified</a></h3>
      </div>
      <div class="grid_1">
        <h3><a href="blog.html">Blog</a></h3>
      </div>
      <div class="grid_5" id="socialicons">
        <h3>CONNECT WITH US</h3>
        <a id="twitter" href="http://twitter.com/#!/x2performance" title="Twitter" target="_blank"></a> <a id="facebook" href="http://www.facebook.com/X2PERFORMANCE" title="Facebook" target="_blank"></a> <a id="youtube" href="http://www.youtube.com/user/TEAMX2PERFORMANCE/featured" title="You Tube" target="_blank"></a> <a id="googleplus" href="https://plus.google.com/109519688499936342953/posts" title="Google Plus" target="_blank"></a> </div>
      <div class="clear"></div>
    </div>
    <div id="footersectiontwo"> <span id="footerlogo"></span>
      <h3><span>MAKE IT HAPPEN <sup>®</sup></span><br/>
        PROUDLY MADE IN THE USA &copy; 2012 Advanced Bio Development LLC</h3>
      <span id="footerlogo2"></span> </div>
  </div>
 
</div>
<script type="text/javascript" src="assets/js/menu.js"></script>
</body>
</html>